<%@page contentType="text/html; charset=utf-8" %>
<%@page import="eduboat.comm.util.ReturnConstant"%>
<%-- 
/**
 * 创建信息
 * ============= jsp名: /work/admin/xtgl/role/role_menu.jsp
 * 作用描述:  显示所有菜单以及当前角色所具有的菜单，新增角色菜单
 * 创建人：fyr
 * 创建时间： 2013-1-18 
 * 修改信息1=============
 * 修改类型: //1.修改bug 2.业务变化修改 修改描述: 修改人： 修改时间：
 */
 --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>智慧校园-后台管理系统</title>
		<%@ include file="/comm/jsp/public.jsp"%>
		<!--通用css-->
		<link rel="stylesheet" type="text/css" media="all" href="<%=path%>/work/comm/css/common.css" />
		<!--通用js-->
		<script type="text/javascript" src="<%=path %>/work/comm/js/public.js"></script>
		<!--树形css-->
		<link rel="stylesheet" href="<%=path%>/comm/plug/tree/css/zTreeStyle/zTreeStyle.css" type="text/css" />
		<!--树形基本js-->
		<script type="text/javascript" src="<%=path%>/comm/plug/tree/js/jquery.ztree.core-3.5.js"></script>
		<script type="text/javascript" src="<%=path%>/comm/plug/tree/js/jquery.ztree.excheck-3.5.js"></script>
		<style>
body {
	background-image: url('');
	min-width: 100px;
}
</style>
<script type="text/javascript">
		$(function(){			
			 initTree();   //初始化树	 
			 $("#btnSave").click(function(){ 	//点击保存，执行保存事件
				saveRoleMenu();		
			});
		});
		var role_code = art.dialog.data("role_code");       //得到从role_list界面传过来的角色编码
		var zNodes ;
		/*
		 *初始化树节点
		 */
		function initTree(){
			ajaxListInitCall({
				url : "<%=path%>/work/admin/xtgl/json/roleMenuInitAction_findRoleMenu.action?role_Meun_TreeVO.role_code="+role_code, //访问页面 
				_callBackOK:initTreeOK,
				beforeSend : function(XMLHttpRequest) {
					$("#tree1_load").css("display","");
					$("#tree1").css("display","none");
			    },
				_errMethod:function(){
					$("#tree1").html("加载失败,请<a href=\"javascript:initTree()\">重试</a>");
					$("#tree1_load").css("display","none");
				}
			});
		}
		
		/*
		 *后台成功返回后执行
		 */
		function initTreeOK(data){
			var tree=data.role_Meun_List;
		  	for(var nodes in tree)		
		     {
		  		tree[nodes].id = tree[nodes].men_sn;
		  		tree[nodes].pId = tree[nodes].parent_sn;
		  		tree[nodes].name = tree[nodes].men_name;
		  		if(tree[nodes].menrole_sn.length!=0){
						tree[nodes].checked=true;									
		       }
		     }
		    zNodes =tree;
			    $.fn.zTree.init($("#tree1"), setting,zNodes);
			    $("#tree1").css("display","");
			    $("#tree1_load").css("display","none");
		}//initTree End
		
		var setting = {
					check: {
					enable: true,
					chkStyle: "checkbox",
					chkboxType: { "Y": "ps", "N": "ps" }
				},
					data: {
						simpleData: {
							enable: true
						}
					}
			};
		/*
		 * 保存角色菜单方法
		 */
		function saveRoleMenu(){
			 		 	$("#btnSave").attr("disabled",true);
			 		 		var tree = $.fn.zTree.getZTreeObj("tree1");
			 		 	 	 var nodes = tree.getCheckedNodes(true);				//得到树中checkbox被选中的节点
			 		 	 	 if(nodes==null||nodes==""){
			 		 	 		$("#btnSave").attr("disabled",false);
			 	 		 	 	art.dialog.alert("至少要选择一个菜单");
								return false;
			  	 		 	 }	 	 
			 		 	var list = new Array();
			 		 	 for(var i=0;i<nodes.length;i++)
						  {
						  	list[i] = nodes[i].id;									//把被选中的checkbox的id放到一个list中，并传给action
						  }
			 		 	ajaxOtherCall({
			 		 		url: "<%=path%>/work/admin/xtgl/json/roleMenuSaveAction_insertRoleMenu.action?role.role_code="+role_code+"&rolemenu="+list,
			 		 		_beforeSendText:"正在加载数据，请稍等",    
			 		 		_callBackOK:function(){
						     	$("#btnSave").attr("disabled",false);
						     	art.dialog.alert("保存成功",function(){},"succeed");
				 		    	}
			 			 	})
			}//saveRoleMenu  END
</script>
	</head>
	<body style="margin-top: 20px">
		<div class="bz_div" style="width: 450px; margin-top: 10px">
			<div class="bz_tit">
				<div style="margin-left: 10px;">
					角色菜单
				</div>
			</div>
			<div class="bz_cont">

				<div id="tree1" class="ztree" style="display: none;text-align: center ;">
			     	 
			     	</div>
			     	<div id="tree1_load" class="ztree" style="text-align: center ;">
			     	  <img src="<%=path %>/comm/images/loading1.gif" alt="" />
			     	</div>

			</div>
			<!---.bz_cont end-->
		</div>
		<!--.bz_div end-->

		<div>
			<input type="button" id="btnSave" class="regbutton3" value="保存"
				style="margin-left: 150px" />
		</div>

	</body>
</html>
